<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>博客分类列表</title>
<style type="text/css">
body {
	text-align: center;
}

a {
	text-decoration: none;
	color: black;
	cursor: pointer;
}
a:hover {
    color: red;
}
.ljyd {
	position: absolute;
	left: 770px;
	top: 30px;
}
.ljydzy {
	position: absolute;
	left: 800px;
	top: 30px;
}
<%--
.fllb {
	position: relative;
	left: 100px;
	top: 50px;
	width: 800px;
	font-size: 30px;
}

.fllb .dgbg {
	height: 50px;
}

.fllb .idxg {
	width: 100px;
}
--%>
.tbyd{
    position: relative;
	left: 150px;
	top: 150px;
}
.qgdyd{
    position: absolute;
    left: 500px;
	top: 30px;
}
table tr th{
    width: 100px;
    height: 100px;
    font-size: 30px;
}
.tbyd .tenakd{
    width: 600px;
}
</style>
</head>
<body onmousemove="pos()">
    <%! int csnumber = 0; String csnamber = "a";%>
	<%
		String strSessionj = (String) request.getSession().getAttribute("namet");
		System.out.println("typelist:" + strSessionj);
		if(strSessionj == null){
			response.getWriter().append("<a href='http://localhost:8089/user_login.html' class='ljyd'>登录</a>");
			response.getWriter().append("<span class='ljydzy'><a href='mainpage.jsp'>&nbsp;&nbsp;&nbsp;返回主页</a></span>");			
		} else {
			response.getWriter().append("<a href='http://localhost:8089/user_personalpage.jsp' class='ljyd'>");
			response.getWriter().append(strSessionj);
			response.getWriter().append("</a>");
			response.getWriter().append("<span class='ljydzy'><a href='mainpage_login.jsp'>返回主页</a></span>");			
		}
	%>
	<!--  
	<a href="http://localhost:8089/user_personalpage.jsp" class="ljyd"><%=strSessionj%></a>
	<span class="ljydzy"><a href="mainpage_login.jsp">返回主页</a></span>
	-->
	<h1 class="qgdyd">博客分类</h1>
	<%!
	    private static final String JDBC_URL = "jdbc:mysql://localhost:3309/blog?useUnicode=true&characterEncoding=utf8";
	    private static final String DB_USER = "root";
	    private static final String DB_PWD = "ZLWL";
	    Map<String, String> hashMaps = new HashMap<String, String>();
	%>
	<%
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
		} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
			e.printStackTrace();
		}
		Connection conn;
		try {
			conn = DriverManager.getConnection(JDBC_URL, DB_USER, DB_PWD);
			Statement stmt = conn.createStatement();
			String sqlz = "select count(id) total from blog_type";
			ResultSet rsz = stmt.executeQuery(sqlz);
			System.out.println("blog_typelist_number1:" + rsz);
			int setnum = 0;
			while (rsz.next()) {
				int getnum = rsz.getInt(1);
				System.out.println("blog_typelist_number1:" + getnum);
				setnum = getnum;
			}
			System.out.println("blog_typelist_number1:" + setnum);
			System.out.println("****************************************");
			String sqly = "select id from blog_type";
			ResultSet rsy = stmt.executeQuery(sqly);
			System.out.println("blog_typelist_number2:" + rsy);
			Map<String, String> hashMap1 = new HashMap<String, String>();
			int i = 1;
			while (rsy.next()) {
			    hashMap1.put("id" + i, rsy.getString("id"));
			    hashMaps.put("id" + i, rsy.getString("id"));
			    System.out.println(hashMap1.get("id" + i));
			    i ++;
			}
			System.out.println("****************************************");
			String sqlx = "select type_name from blog_type";
			ResultSet rsx = stmt.executeQuery(sqlx);
			System.out.println("blog_typelist_number3:" + rsx);
			Map<String, String> hashMap2 = new HashMap<String, String>();
			int j = 1;
			while (rsx.next()) {
			    hashMap2.put("type_name" + j, rsx.getString("type_name"));             
			    System.out.println(hashMap2.get("type_name" + j));
			    j ++;
			}
			System.out.println("****************************************");
			/*
			StringBuffer sbf = new StringBuffer();
			sbf.append("<table border='1' class='tbyd'>");
			sbf.append("<tr>");
			sbf.append("<th>ID</th>");
			sbf.append("<th>分类</th>");
			sbf.append("</tr>");
			sbf.append("</table>");
			*/
			response.getWriter().append("<table border='1' class='tbyd' id='cs'>");
			response.getWriter().append("<tr>");
			response.getWriter().append("<th>ID</th>");
			response.getWriter().append("<th class='tenakd'>分类</th>");
			response.getWriter().append("</tr>");
			response.getWriter().append("</table>");
			int k = 1;
			while(k < (setnum + 1)) {
			csnumber = k;
			/*
			String sqls = "select type_name from blog_type where id = " + csnumber;
			ResultSet rss = stmt.executeQuery(sqls);
			String setstrs = "0";
			while (rss.next()) {
				String getstrs = rss.getString("type_name");
				setstrs = getstrs;
			}
			rss.close();
			csnamber = setstrs;
			*/
			csnamber = hashMap2.get("type_name" + k);
			System.out.println("csnumber:" + csnumber);
			System.out.println("csnamber:" + csnamber);
			System.out.println(hashMap1.get("id" + k));
			System.out.println(hashMap2.get("type_name" + k));
			System.out.println("Maps_id:" + hashMaps.get("id" + k));
			response.getWriter().append("<table border='1' class='tbyd' id='" + hashMap1.get("id" + k) + "'>");
			response.getWriter().append("<tr>");
			response.getWriter().append("<th>");
			response.getWriter().append("<a onclick='djcsid()'>");
			response.getWriter().append(hashMap1.get("id" + k));
			response.getWriter().append("</a>");
			response.getWriter().append("</th>");
			response.getWriter().append("<th class='tenakd'>");
			response.getWriter().append("<a onclick='djcsid()'>");
			response.getWriter().append(hashMap2.get("type_name" + k));
			response.getWriter().append("</a>");
			response.getWriter().append("</th>");
			response.getWriter().append("</tr>");
			response.getWriter().append("</table>");
			k ++;
			}
			rsx.close();
			rsy.close();
			rsz.close();
			stmt.close();
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	%>
	<form method="post" name="pasorm" action="blog_single_typelist.jsp">
		<input type='hidden' name="csflname">
		<input type='hidden' name="csflnames">
	</form>
	<!--  
	<span>鼠标当前在:</span>
	<span id="show"></span>
	-->
	<br><br><br><br><br><br><br><br><br><br>
	<script type="text/javascript">
	var diffiernum = 0;
	function fnGetTable(oEl) {
		try {
			while (null != oEl && oEl.tagName != "TABLE") {
				oEl = oEl.parentElement;
			}
			return oEl;
		} catch (e) {
			return null;
		}
	}
	function pos() {
		try {
			oElement = document.elementFromPoint(event.x, event.y);
			oElement = fnGetTable(oElement);
			if (oElement.tagName == "TABLE")
				//show.innerText = oElement.id;
			    diffiernum = oElement.id;
		} catch (e) {
		}
	}
	function setinput(csflname,csflnames){
		document.pasorm.csflname.value = csflname;
		document.pasorm.csflnames.value = csflnames;
	    document.pasorm.submit();
	}
	function djcsid(){
		setinput(diffiernum,"mdzz");
	}
	</script>
	<%-- 
	<table border="1">
		<tr>
			<th>ID</th>
			<th>分类</th>
		</tr>
	</table>
    --%>
	<%-- 
	<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
		url="jdbc:mysql://localhost:3309/blog" user="root" password="ZLWL" />
	<sql:query dataSource="${snapshot}" var="result">
    select * from blog_type;
    </sql:query>
    <sql:query dataSource="${snapshot}" var="result1">
    select * from blog_type order by id desc limit 1;
    </sql:query>
    <h1>博客分类</h1>
    <!--  
    <c:forEach var="raw" items="${result1.rows}">
		<c:out value="${raw}" />
		<c:out value="${raw.id}" />
	</c:forEach>
	<c:forEach var="rbw" items="${result.rows}">
		<c:out value="${rbw}" />
		<c:out value="${rbw.remark}" />
	</c:forEach>
	-->
	<table border="1" class="fllb">
		<tr class="dgbg">
			<th class="idxg">ID</th>
			<th>分类</th>
		</tr>
		<c:forEach var="row" items="${result.rows}" begin="0" end="0">
			<tr class="dgbg">
				<td class="idxg"><a href="http://localhost:8089/blog_single_typelist.jsp"><c:out value="${row.id}" /></a></td>
				<td><a href="http://localhost:8089/blog_single_typelist.jsp"><c:out value="${row.type_name}" /></a></td>
			</tr>
		</c:forEach>
		<c:forEach var="row" items="${result.rows}" begin="1" end="1">
			<tr class="dgbg">
				<td class="idxg"><a href="http://localhost:8089/blog_single_typelist.jsp"><c:out value="${row.id}" /></a></td>
				<td><a href="http://localhost:8089/blog_single_typelist.jsp"><c:out value="${row.type_name}" /></a></td>
			</tr>
		</c:forEach>
		<c:forEach var="raw" items="${result1.rows}">
		    <%!
		        int flzs = 0;
		    %>
		    <c:out value="${raw.id}" />
	    </c:forEach>
	</table>
	--%>
</body>
</html>